package com.webserver.core;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Program: WebServerTomcat
 * @Author: Evan
 * @Date: 2022-05-16 08:14
 * @Description: web容器
 * @Version: V1.0
 */
public class WebServer {
    private ServerSocket serverSocket;

    public WebServer(){
        try {
            System.out.println("正在启动服务器");
            serverSocket = new ServerSocket(8088);
            System.out.println("服务器已经启动");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void start(){
        try {
            while (true) {
                System.out.println("等待客户端链接");
                Socket socket = serverSocket.accept();
                System.out.println("一个客户端已经链接");

                /*启动线程来处理客户端交互*/
                ClientHandler handler = new ClientHandler(socket);
                Thread t = new Thread(handler);
                t.start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        WebServer webServer = new WebServer();
        webServer.start();
    }
}
